var Rectangle = AbstractPrimitive.extend({
    init: function(origin, width, height){
        this._origin = origin;
        this._width = width;
        this._height = height;
    },
    setOrigin: function(origin){
        this._origin = origin;
    },
    getOrigin: function(){
        return this._origin;
    },
    setWidth: function(width){
        this._width = width;
    },
    getWidth: function(){
        return this._width;
    },
    setHeight: function(height){
        this._height = height;
    },
    getHeight: function(){
        return this._height;
    },
    getCenter: function(){
      return   new Point(this.getOrigin().getX() + (this.getWidth() / 2), this.getOrigin().getY() + (this.getHeight() / 2));
    },
    getIntersectionFromCenterToPoint: function(point){

        var tLVertice = this.getOrigin(),
            tRVertice = new Point(this.getOrigin().getX() + this.getWidth() , this.getOrigin().getY()),
            bLVertice = new Point(this.getOrigin().getX(), this.getOrigin().getY() + this.getHeight()),
            bRVertice = new Point(this.getOrigin().getX() + this.getWidth(), this.getOrigin().getY() + this.getHeight());

        var edges = [
            new Line(tLVertice, tRVertice),
            new Line(tRVertice, bRVertice),
            new Line(bRVertice, bLVertice),
            new Line(bLVertice, tLVertice)
        ];

        var joiner = new Line(this.getCenter(), point);

        for (var i = edges.length - 1; i >= 0; --i){
            var intersection = edges[i].getIntersection(joiner);
            if (intersection !== null){
                return intersection;
            }
        }

        return null;
    }
});